﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ManageEmployees.Properties;
using ManageEmployees.Models;

namespace ManageEmployees
{
    public partial class fOrganizationInfo : fBase
    {
        #region Constructors
        public fOrganizationInfo()
        {
            InitializeComponent();
        }

        private Organization objOrgan;
        public fOrganizationInfo(Organization _objOrgan)
        {
            InitializeComponent();
            objOrgan = _objOrgan;
        }
        #endregion

        #region Form Load
        private void fOrganizationInfo_Load(object sender, EventArgs e)
        {
            if (objOrgan == null)
            {
                Text = Resources.OrganizationFormAdd;
            }
            else
            {
                Text = Resources.OrganizationFormUpdate;
            }
        }
        #endregion

        #region Events
        private void iSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
        }

        private void fOrganizationInfo_KeyDown(object sender, KeyEventArgs e)
        {
            if (ModifierKeys == Keys.Control)
            {
                if (e.KeyCode == Keys.S)
                {
                    Save();
                }
            }
        }

        private void iExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Close();
        }
        #endregion

        #region Functions
        private void Save()
        {
            Organization objOrgan = new Organization();
            bool isFlag;
            isFlag = Utility.OrganizationsInsert(objOrgan);
            isFlag = false;
            if (isFlag)
            {
                XtraMessageBox.Show(Resources.AddSuccess, Resources.Notification, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show(Resources.AddError, Resources.Notification, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }
        #endregion
    }
}